package com.jcooky.tutorfs.proxy.protocol;

import org.apache.mina.core.buffer.IoBuffer;

public abstract class AbstractMessage {
	public static final int TYPE_REQ_LS = 0x01;
	public static final int TYPE_REQ_WRITE = 0x02;
	public static final int TYPE_RES_WRITE = 0x03;
	public static final int TYPE_REQ_READ = 0x04;
	public static final int TYPE_RES_READ = 0x05;
	public static final int TYPE_REQ_MKDIR = 0x06;
	public static final int TYPE_RES_OK = 0x07;
	public static final int TYPE_REQ_RMDIR = 0x08;
	
	public abstract void fromBytes(IoBuffer buf);
	public abstract void toBytes(IoBuffer buf);
	public abstract int length();
	
	public static AbstractMessage getMessage(int type) {
		switch(type) {
		case TYPE_REQ_MKDIR:
			return new ReqMkdir();
		case TYPE_RES_OK:
			return new ResOk();
		case TYPE_REQ_RMDIR:
			return new ReqRmdir();
		case TYPE_REQ_WRITE:
			return new ReqWrite();
		case TYPE_REQ_READ:
			return new ReqRead();
		case TYPE_RES_READ:
			return new ResRead();
		}
		
		return null;
	}
}
